home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xml;
-
- import com.extensibility.plugin.PluginRegistry;
- import com.extensibility.plugin.api.URIScheme;
- import com.extensibility.plugin.api.URISchemeAdapter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.OutputStreamWriter;
- import java.io.Reader;
- import java.io.Writer;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
-
- public class URIUrlScheme extends URISchemeAdapter {
- private URL url;
-
- public static void registerPlugin(PluginRegistry var0) {
- var0.registerPlugin("URIScheme10", Class.forName("com.extensibility.xml.URIUrlScheme"), "URIUrlcheme", 65537);
- }
-
- public URIUrlScheme() {
- this.url = null;
- }
-
- public URIUrlScheme(URL var1) {
- this.url = var1;
- }
-
- public void registerSchemes(URIScheme.Manager var1) {
- var1.registerScheme("http", Class.forName("java.net.URL"), this);
- var1.registerScheme("ftp", Class.forName("java.net.URL"), this);
- }
-
- public URIScheme construct(String var1, String var2) {
- URL var3 = null;
-
- try {
- var3 = new URL(var2);
- } catch (Exception var5) {
- }
-
- return new URIUrlScheme(var3);
- }
-
- public URIScheme construct(Object var1) {
- return new URIUrlScheme((URL)var1);
- }
-
- public URIScheme construct(String var1) {
- URL var2 = null;
-
- try {
- var2 = new URL(this.url, var1);
- } catch (Exception var4) {
- }
-
- return new URIUrlScheme(var2);
- }
-
- public String computeRelative(URIScheme var1) {
- URIUrlScheme var2 = (URIUrlScheme)var1;
- URL var3 = var2.url;
- String var4;
- if (this.url.getProtocol().equals(var3.getProtocol()) && this.url.getHost().equals(var3.getHost()) && this.url.getPort() == var3.getPort()) {
- String var5 = this.url.getFile();
- String var6 = var3.getFile();
- int var7 = 0;
-
- int var8;
- for(var8 = var6.indexOf(var7, 47); var8 > 0 && var6.regionMatches(var7, var5, var7, var8 - var7 + 1); var8 = var6.indexOf(var7, 47)) {
- var7 = var8 + 1;
- }
-
- int var9 = var8;
-
- StringBuffer var10;
- for(var10 = new StringBuffer(); var8 > 0; var8 = var6.indexOf(var8, 47)) {
- var10.append("../");
- }
-
- var10.append(var5.substring(var9));
- var4 = var10.toString();
- } else {
- var4 = this.url.toExternalForm();
- }
-
- return var4;
- }
-
- public URIScheme toParent() {
- String var1 = this.url.getFile();
- int var2 = var1.lastIndexOf(47);
- URL var3 = this.url;
- if (var2 >= 0) {
- var1 = var1.substring(var2 + 1);
- }
-
- try {
- var3 = new URL(this.url.getProtocol(), this.url.getHost(), this.url.getPort(), var1);
- } catch (MalformedURLException var5) {
- }
-
- return new URIUrlScheme(var3);
- }
-
- public String getScheme() {
- return this.url.getProtocol();
- }
-
- public String getUIName() {
- return this.url.toExternalForm();
- }
-
- public long getLength() {
- long var1 = -1L;
-
- try {
- URLConnection var3 = this.url.openConnection();
- var1 = (long)var3.getContentLength();
- } catch (Exception var4) {
- }
-
- return var1;
- }
-
- public InputStream createInputStream() throws IOException {
- return this.url.openConnection().getInputStream();
- }
-
- public Reader createReader() throws IOException {
- return new XMLReader(this.url.openConnection().getInputStream());
- }
-
- public Writer createWriter() throws IOException {
- return new OutputStreamWriter(this.createOutputStream());
- }
-
- public OutputStream createOutputStream() throws IOException {
- HttpURLConnection var1 = (HttpURLConnection)this.url.openConnection();
- ((URLConnection)var1).setAllowUserInteraction(false);
- var1.setRequestMethod("HEAD");
- long var2 = ((URLConnection)var1).getDate();
- int var4 = var1.getResponseCode();
- if (var4 == 200) {
- var1.disconnect();
- var1 = (HttpURLConnection)this.url.openConnection();
- ((URLConnection)var1).setDoOutput(true);
- ((URLConnection)var1).setAllowUserInteraction(false);
- var1.setRequestMethod("DELETE");
- ((URLConnection)var1).connect();
- var4 = var1.getResponseCode();
- }
-
- var1.disconnect();
- var1 = (HttpURLConnection)this.url.openConnection();
- var1.setRequestMethod("PUT");
- ((URLConnection)var1).setDoOutput(true);
- ((URLConnection)var1).setAllowUserInteraction(false);
- ((URLConnection)var1).connect();
- OutputStream var5 = ((URLConnection)var1).getOutputStream();
- if (var5 == null) {
- throw new IOException();
- } else {
- return new WrapOutputStream(var5, var1);
- }
- }
-
- public boolean exists() {
- try {
- if (this.url == null) {
- boolean var10 = false;
- return var10;
- } else {
- HttpURLConnection var7 = (HttpURLConnection)this.url.openConnection();
- if (var7 == null) {
- boolean var9 = false;
- return var9;
- } else {
- ((URLConnection)var7).setDoInput(true);
- var7.setRequestMethod("HEAD");
- ((URLConnection)var7).setDoOutput(false);
- ((URLConnection)var7).setAllowUserInteraction(false);
- ((URLConnection)var7).connect();
- long var2 = ((URLConnection)var7).getDate();
- int var4 = var7.getResponseCode();
- var7.disconnect();
- Object var8 = null;
- if (var4 == 200) {
- boolean var11 = true;
- return var11;
- } else {
- boolean var5 = false;
- return var5;
- }
- }
- }
- } catch (IOException var6) {
- Object var1 = null;
- boolean var3 = false;
- return var3;
- }
- }
-
- public boolean equals(URIScheme var1) {
- URIUrlScheme var2 = (URIUrlScheme)var1;
- return this.url.sameFile(var2.url);
- }
-
- public int compareTo(URIScheme var1) {
- URIUrlScheme var2 = (URIUrlScheme)var1;
- boolean var3 = this.url.sameFile(var2.url);
- int var4 = 0;
- if (!var3) {
- var4 = this.url.toExternalForm().compareTo(var2.url.toExternalForm());
- }
-
- return var4;
- }
-
- public String getShortName() {
- String var1 = this.url.getFile();
- int var2 = var1 != null ? var1.lastIndexOf("/") : -1;
- if (var2 >= 0) {
- var1 = var1.substring(var2 + 1);
- }
-
- return var1;
- }
-
- public String getFullPath() {
- return this.url.toExternalForm();
- }
- }
-